﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using FSS.BLL.Entities;
using FSS.BLL.Services;
using FSS.BLL;

namespace SalesManagement.Controls.List
{
    public partial class InOutComeContentForm : System.Web.UI.UserControl
    {
        public event EventHandler SaveClick;
        private void OnSaveClick()
        {
            if (SaveClick != null)
            {
                SaveClick(this, EventArgs.Empty);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void Show()
        {
            this.winDetails.Show();
        }
        public void Show(string inoutCCId)
        {
            InOutComeContentEntity inoutCCE = new InOutComeContentEntity();
            InOutComeContentService inoutCCS = InOutComeContentService.GetInstance();
            inoutCCE.InOutComeId = int.Parse(inoutCCId);
            inoutCCE = inoutCCS.LoadByPrimaryKey(inoutCCE);
            if (null == inoutCCE)
                return;
            hdfInOutCCId.Value = inoutCCE.InOutComeId;
            txtInOutComeName.Text = inoutCCE.InOutComeName;
            txtType.Text = inoutCCE.Type;
            txtDisplayOrder.Text = inoutCCE.DisplayOrder.ToString();
            txtDescription.Text = inoutCCE.Description;
            ckbIsActive.Checked = inoutCCE.IsActive;
            this.winDetails.Show();
        }
        public void ShowAndReset()
        {
            this.FormPanel1.Reset();
            this.winDetails.Show();
        }
        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            InOutComeContentEntity inoutCCE = new InOutComeContentEntity();
            InOutComeContentService inoutCCS = InOutComeContentService.GetInstance();
            if ("" != hdfInOutCCId.Value.ToString())
            {
                string inoutCCId = hdfInOutCCId.Value.ToString();
                inoutCCE.InOutComeId = int.Parse(inoutCCId);
                inoutCCE = inoutCCS.LoadByPrimaryKey(inoutCCE);
                inoutCCE.InOutComeName = txtInOutComeName.Text;
                inoutCCE.Type = txtType.Text;
                inoutCCE.DisplayOrder = int.Parse(txtDisplayOrder.Text);
                inoutCCE.Description = txtDescription.Text;
                inoutCCE.IsActive = ckbIsActive.Checked;
                inoutCCE.UpdatedDate = DateTime.Now;
                inoutCCE.UpdatedBy = FSSContext.Current.User.EmployeeId;
                inoutCCS.Update(inoutCCE);
            }
            else
            {
                inoutCCE.InOutComeName = txtInOutComeName.Text;
                inoutCCE.Type = txtType.Text;
                inoutCCE.DisplayOrder = int.Parse(txtDisplayOrder.Text);
                inoutCCE.Description = txtDescription.Text;
                inoutCCE.IsActive = ckbIsActive.Checked;
                inoutCCE.CreatedDate = DateTime.Now;
                inoutCCE.CreatedBy = FSSContext.Current.User.EmployeeId;
                inoutCCE.UpdatedDate = DateTime.Now;
                inoutCCE.UpdatedBy = FSSContext.Current.User.EmployeeId;
                inoutCCS.Insert(inoutCCE);
            }
            this.winDetails.Hide();
            OnSaveClick();
        }
    }
}